﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using drive;
using ProtoBuf;
using System.IO;

namespace CarDriver
{
    class car_driver
    {
        server_client client = new server_client();
        drive.drive d = new drive.drive(); //todo change namespace proto or something

        public car_driver()
        {
            d.direction = drive.drive.EDirection.STOP;
            d.wheel_angle = 0;
        }

        public void set_wheel_angle(int val)
        {
            d.wheel_angle = val;
            send_update();
        }

        private void send_update()
        {
            using (Stream stream = new MemoryStream())
            {
                Serializer.Serialize(stream, d);
                byte[] data = new byte[stream.Length];
                stream.Seek(0, SeekOrigin.Begin);
                stream.Read(data, 0, data.Length);   
                message msg = new message(1, data);
                msg.encode_header();
                client.send(msg);
            }
        }
    }
}
